package com.service;

import com.mapper.JdWarehouseMapper;
import com.pojo.JdWarehouse;
import com.pojo.JdWarehouseExample;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class WarehouseService {
    
    @Resource
    private JdWarehouseMapper warehouseMapper;
    
    @Transactional (propagation = Propagation.REQUIRES_NEW, readOnly = true)
    public JdWarehouse queryByKey(int w_num){
        return warehouseMapper.selectByPrimaryKey(w_num);
    }
    
    @Transactional (propagation = Propagation.REQUIRES_NEW, readOnly = true)
    public List<JdWarehouse> queryByType(JdWarehouse warehouse) {
        JdWarehouseExample example = new JdWarehouseExample();
        JdWarehouseExample.Criteria criteria = example.createCriteria();
        if (warehouse != null){
            if (warehouse.getW_id()!=null){
                criteria.andW_idEqualTo(warehouse.getW_id());
            }
            if (warehouse.getW_name()!=null){
                criteria.andW_nameLike("%"+ warehouse.getW_name()+"%");
            }
        }
        return warehouseMapper.selectByExample(example);
    }
    
    
    
}
